!! 对文献进行重排序
program main

    use argv_module, only: argv
    use seakeeping_filesystem, only: operator(.join.)
    use rerank_io, only: read_ranks, read_papers, write_papers, write_ranks
    use rerank_string, only: string_t
    implicit none
    integer, allocatable :: ranks(:)
    type(string_t), allocatable :: papers(:)
    character(:), allocatable :: folder, IRRFT

    print *, 'Rerank my papers (rerank v1.0.0)'

    folder = argv(1)
    if (len(folder) == 0) folder = 'data'
    print *, 'Reading papers from folder: ', folder

    IRRFT = argv(2)
    if (len(IRRFT) == 0) IRRFT = 'F'
    print *, 'Reading ranks from text: ', IRRFT

    if (IRRFT == 'T') then
        call write_ranks(folder.join.'text.txt', folder.join.'ranks0.txt')
        call read_ranks(folder.join.'ranks0.txt', ranks)
    else
        call read_ranks(folder.join.'ranks.txt', ranks)
    end if

    call read_papers(folder.join.'papers.txt', papers)
    call write_papers(folder.join.'newpapers.txt', ranks, papers, folder.join.'table.txt')

    print *, '*** Note ***'
    print *, 'text.txt      : text'
    print *, 'ranks.txt     : manual ranks'
    print *, 'ranks0.txt    : ranks from text'
    print *, 'newpapers.txt : new papers'
    print *, 'table.txt     : index old ranks to new ranks'

end program main
